<template>
  <div>
    <h3>******日志******</h3>
    <div style="height:420px;width:100%;overflow:auto;">
      <div v-for="item in log">{{item}}</div>
    </div>
  </div>
</template>

<script>

import dayjs from 'dayjs'

export default {
  name: "Dayjs",
  data() {
    return {
      content: '',
      log: [],
    };
  },
  created() {
  },
  mounted() {
    this.log.push('获取现在时间')
    this.log.push(dayjs().format("YYYY-MM-DD HH:mm:ss"))
    this.log.push(dayjs().startOf('hour').format("HH"))
    this.log.push(dayjs().startOf('minute').format("mm"))
    this.log.push(dayjs().startOf('second').format("ss"))

    this.log.push('获取当前年')
    this.log.push(dayjs().format("YYYY"))
    this.log.push('获取今年第一天')
    this.log.push(dayjs().startOf('year').format('YYYY-MM-DD'))

    this.log.push('获取当天和现在时间')
    this.log.push(dayjs().format("YYYY-MM-DD"))
    this.log.push('获取当天0点和23:59:59')
    this.log.push(dayjs().startOf('date').format('YYYY-MM-DD HH:mm:ss'))
    this.log.push(dayjs().endOf('date').format('YYYY-MM-DD HH:mm:ss'))

    this.log.push('获取当月')
    this.log.push(dayjs().startOf('month').format('YYYY-MM'))
    this.log.push(dayjs().startOf('month').month())
    this.log.push(dayjs().startOf('month').format('MM'))
    this.log.push('获取当月第一天')
    this.log.push(dayjs().startOf('month').format('YYYY-MM-DD'))

    this.log.push('获取本周第一天')
    // 需要本地化，默认的周第一天是周日
    this.log.push(dayjs().startOf('week').format('YYYY-MM-DD'))
    this.log.push(dayjs().subtract(dayjs().day() ? dayjs().day() - 1 : 6, "day").format("YYYY-MM-DD"))

    this.log.push('今天往后的第N天')
    this.log.push(dayjs().add(2, 'day').format('YYYY-MM-DD'))
    this.log.push('今天往前的第N天')
    this.log.push(dayjs().add(-2, 'day').format('YYYY-MM-DD'))

    this.log.push('两个日期的差')
    this.log.push(dayjs('2022-02-10').diff('2022-02-01','day'))
    this.log.push(dayjs('2022-02-01').diff('2022-02-10','day'))
    this.log.push(dayjs('2022-02-10').diff('2022-02-01','month'))
    this.log.push(dayjs('2022-02-10').diff('2022-02-01','hour'))

  },
  methods: {
  }
};
</script>
